@extends('admin.adminbase')
@section('content')


    <section class="hbox stretch">
        @include("admin.public.left")

        <aside>
            <section class="vbox">
                <header class="header bg-white b-b clearfix">
                    <form class="talbe-search" method="get" action="">
                        <div class="row m-t-sm">
                            <div class="col-sm-12 m-b-xs">
                                <div class="btn-group" role="group">
                                    <strong style="line-height:30px;">编辑Banner</strong>
                                </div>

                                <div class="btn-group pull-right">
                                    <a role="button" class="btn btn-info btn-sm " title="返回" onclick="history.back()">
                                        <i class="glyphicon glyphicon-arrow-left"></i>&nbsp;返回
                                    </a>
                                </div>

                            </div>
                        </div>
                    </form>
                </header>
                <section class="scrollable  wrapper w-f">
                    <section class="panel panel-default ">
                        <div class="row m-l-none m-r-none bg-light lter">
                            <div class="container" style="padding: 20px 0px">
                                <form id="formclass" class="form-horizontal" style="padding-top: 15px;">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">轮播图 <span class="red">*</span></label>
                                        <div class="col-sm-4 ">
                                            <img src="{{ config('config.picHostPrefix').$info->small_img }}" id="file_img" width="80" height="80">
                                            <input type="file" class="form-control" id="input_file" data-src="{{ url('upload/img') }}" placeholder="请输入标题">
                                            <input type="hidden" id="input_hidden"  name="pic_url" value="{{$info->img}}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">展示位置 <span class="red">*</span></label>
                                        <div class="col-sm-4 ">
                                            <select  class="form-control" name="position">
                                                <option value="0">请选择</option>
                                                <?php
                                                $positionList = \App\Http\Util\BannerPosition::getList();
                                                ?>
                                                @foreach($positionList as $position)
                                                    <option value="{{ $position['value'] }}" @if($position['value'] == $info->position) selected="selected" @endif>{{ $position['label'] }}</option>
                                                @endforeach
                                            </select>
                                        </div>
                                    </div>

                                    <input type="hidden" name="site" value="{{ \App\Http\Util\Site::WEB }}">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">跳转地址<span class="red">*</span></label>
                                        <div class="col-sm-4 ">
                                            <input type="text" class="form-control" name="link_url" value="{{ $info->link_url }}" required="required"
                                                   placeholder="请输入跳转地址">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">备注 </label>
                                        <div class="col-sm-4 ">
                                            <textarea name="remark" rows="5" cols="50">{{ $info->remark }}</textarea>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-sm-3">状态<span class="red">*</span></label>
                                        <div class="col-sm-4" style="margin-top: 5px">
                                            <input type="radio" id="status1" name="status" @if($info->status == \App\Http\Util\Status::ON) checked @endif value="1">
                                            <label for="status1">启用</label>
                                            <input type="radio" id="status0" name="status" @if($info->status == \App\Http\Util\Status::OFF) checked @endif value="2">
                                            <label for="status0">禁用</label>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label"></label>
                                        <div class="col-sm-2 ">
                                            <button role="button" class="btn btn-default" addparm="" type="submit">提交</button>
                                            <input type="checkbox" id="back">
                                            <label for="back">返回列表</label>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </section>
                </section>
            </section>
        </aside>
    </section>
@endsection
@section('addscript')
    <script>
        $(function(){
            $("#input_file").change(function(){
                changePic("input_file","file_img","input_hidden")
            });

            //提交表单
            $('#formclass').on('submit',function(){
                var data = $(this).serialize();
                var checked = $('#back').is(':checked');
                //验证表单
                var picUrl = $('input[name=pic_url]').val();
                if(!picUrl){
                    layer.alert('请上传轮播图');
                    return false;
                }

                var position = $('select[name=position]').val();
                if(position == 0){
                    layer.alert('请选择轮播图位置');
                    return false;
                }

                $.post("{{ url('admin/banner/edit/'.$info->id) }}",data,function(data){
                    layer.msg(data.msg);
                    if(data.success){
                        if(checked){
                            setTimeout(function(){
                                location.href = "{{ url('admin/banner') }}";
                            },1500);
                        }else {
                            location.reload();
                        }
                    }
                });
                return false;
            });

        });
    </script>
@endsection
